package com.yhn.init.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhn.init.common.BaseResponse;
import com.yhn.init.common.DeleteRequest;
import com.yhn.init.common.ResultUtils;
import com.yhn.init.model.dto.financialDetails.FinancialDetailsAddRequest;
import com.yhn.init.model.dto.financialDetails.FinancialDetailsQueryRequest;
import com.yhn.init.model.dto.financialDetails.FinancialDetailsUpdateRequest;
import com.yhn.init.model.vo.FinancialDetailsVO;
import com.yhn.init.service.FinancialDetailsService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;


/**
 * 财务尾款
 *
 * @author yhnyhn123
 * @email 2236751002@qq.com
 * @date 2024-03-08 20:36:42
 */
@RestController
@RequestMapping("/financialdetails")
public class FinancialDetailsController {

    @Resource
    private FinancialDetailsService financialDetailsService;

    /**
     * 列表,分页
     */
    @GetMapping("/list")
    //@SaCheckPermissions("furniture/financialdetails/list")
    public BaseResponse<Page<FinancialDetailsVO>> listByPage(@RequestBody FinancialDetailsQueryRequest financialDetailsQueryRequest) {
        Page<FinancialDetailsVO> page = financialDetailsService.queryPage(financialDetailsQueryRequest);
        return ResultUtils.success(page);
    }


    /**
     * 获取单个信息
     */
    @GetMapping("/info/{id}")
    //@SaCheckPermissions("furniture/financialdetails/info")
    public BaseResponse<FinancialDetailsVO> getInfoById(@PathVariable("id") Long id) {
        FinancialDetailsVO financialDetails = financialDetailsService.getInfoById(id);

        return ResultUtils.success(financialDetails);
    }


    /**
     * 保存
     */
    @PostMapping("/save")
    @SaCheckPermission(value = {"/furniture/financial/add", "root"}, mode = SaMode.OR)
    public BaseResponse<FinancialDetailsVO> save(@RequestPart("receiptPhoto") MultipartFile receiptPhoto,
                                                 FinancialDetailsAddRequest financialDetailsAddRequest) {
        return ResultUtils.success(financialDetailsService.saveFinancialDetails(financialDetailsAddRequest, receiptPhoto));
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@SaCheckPermissions("furniture/financialdetails/update")
    public BaseResponse<Boolean> update(@RequestBody FinancialDetailsUpdateRequest financialDetailsUpdateRequest) {
        boolean result = financialDetailsService.updateFinancialDetails(financialDetailsUpdateRequest);

        return ResultUtils.success(result);
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    //@SaCheckPermissions("furniture/financialdetails/delete")
    public BaseResponse<Boolean> delete(@RequestBody DeleteRequest deleteRequest) {
        boolean result = financialDetailsService.deleteById(deleteRequest);
        return ResultUtils.success(result);
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteBatch")
    //@SaCheckPermissions("furniture/financialdetails/delete")
    public BaseResponse<Boolean> deleteBatch(@RequestBody Long[] ids) {
        boolean result = financialDetailsService.deleteBatchByIds(ids);
        return ResultUtils.success(result);
    }
}
